package com.gzist.elderlyserviceplatform.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzist.elderlyserviceplatform.common.Result;
import com.gzist.elderlyserviceplatform.entity.dto.ActivityRegistrationQueryDTO;
import com.gzist.elderlyserviceplatform.entity.dto.ActivityRegistrationReviewDTO;
import com.gzist.elderlyserviceplatform.entity.po.ActivityRegistration;
import com.gzist.elderlyserviceplatform.entity.vo.ActivityRegistrationVO;
import com.gzist.elderlyserviceplatform.entity.vo.HomePageInfoCountVOO;
import com.gzist.elderlyserviceplatform.service.ActivityRegistrationService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 活动报名表
 */
@RestController
@Tag(name = "活动报名管理")
@RequestMapping("/api/admin/activityRegistration")
@RequiredArgsConstructor
public class ActivityRegistrationControllerA {

    private final ActivityRegistrationService activityRegistrationService;

    @PostMapping("/list")
    @Operation(summary = "活动报名列表查询", description = "分页查询活动报名信息")
    public Result<Page<ActivityRegistrationVO>> listActivityRegistration(
            @RequestBody
            @Parameter(description = "查询参数") ActivityRegistrationQueryDTO queryDTO
    ) {
        return Result.success(activityRegistrationService.queryPage(queryDTO), "查询成功");
    }

    /**
     * 审核活动报名
     */
    @PostMapping("/review")
    @Operation(summary = "审核活动报名", description = "根据报名id进行审核活动报名")
    public Result<String> reviewActivityRegistration(
            @RequestBody
            @Parameter(description = "审核参数") ActivityRegistrationReviewDTO reviewDTO
    ) {
        activityRegistrationService.reviewActivityRegistration(reviewDTO);
        return Result.success("审核成功");
    }

    /**
     * 查询单个活动报名详情
     */
    @GetMapping("/detail/{id}")
    @Operation(summary = "查询单个活动报名详情", description = "根据id查询活动报名详情")
    public Result<ActivityRegistration> getActivityRegistration(
            @PathVariable
            @Parameter(description = "活动报名id") String id
    ) {
        return Result.success(activityRegistrationService.getById(id), "查询成功");
    }

    /**
     * 查询各个活动以及其报名人数接口
     */
    @GetMapping("/count")
    @Operation(summary = "查询各个活动以及其报名人数", description = "查询各个活动以及其报名人数")
    public Result<List<HomePageInfoCountVOO>> countActivityRegistration() {
        List<HomePageInfoCountVOO> array = activityRegistrationService.countActivityRegistration();
        return Result.success(array, "查询成功");
    }

    /**
     * 删除活动报名
     */
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除活动报名", description = "根据id删除活动报名")
    public Result deleteActivityRegistration(
            @PathVariable
            @Parameter(description = "活动报名id") String id
    ) {
        activityRegistrationService.removeById(id);
        return Result.success("删除成功");
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "批量删除活动报名", description = "根据id集批量删除活动报名")
    public Result deleteBatchActivityRegistration(
            @RequestBody
            @Parameter(description = "活动报名id集") String[] ids
    ) {
        activityRegistrationService.removeByIds(Arrays.asList(ids));
        return Result.success("批量删除成功");
    }
}